package com.sl.au.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.sl.au.entity.Account;
import com.sl.au.entity.UseCountView;
import com.sl.au.service.UseCountService;

@RestController
@RequestMapping(value="/ui/useCount")
public class UseCountController extends BaseController{
	
	@Autowired
	UseCountService useCountService;
	
	@RequestMapping(method = RequestMethod.GET)
    public ModelAndView index(){
        ModelAndView modelAndView=createLayoutView("publicFunction/useCountIndex");
        return modelAndView;
    }
	
	
	@RequestMapping(value = "/getpage", method = RequestMethod.GET)
	public Map<String, Object> getpage(HttpServletRequest request) {
		Map<String,Object> map = new HashMap<String,Object>();
		Account a = this.getMyAccount();
		int start = Integer.parseInt(request.getParameter("start"));
		int length = Integer.parseInt(request.getParameter("length"));
		//String superior = a.getUser().getSaleArea().getSuperior(); //获取部门信息
		//String superior = "销售处";
		String key = request.getParameter("key");
        List<UseCountView> users = null;
		users = useCountService.getMyPage(start, length, key);
		long count =0;		
		count=useCountService.getCount(key);
		System.out.println(count);
		map.put("data", users);
		map.put("draw", request.getParameter("draw"));
		map.put("recordsFiltered", count);
		map.put("recordsTotal", count);
		return map;
	}
}
